<template>
	<view>
		<empty v-if="list.length==0"></empty>
		<collectItem @del="del(item.shop_id)" :item="item" v-for="(item,i) in list" :key='i'></collectItem>
		<u-loadmore v-show="list.length>9" :status="status" icon-type="flower" bg-color="transperant" margin-top="30"
		 margin-bottom="30" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				status: 'loadmore',
				list:[]
			};
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getList()
		},
		onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			this.getList()
		},
		onLoad() {
			this.getList()
		},
		methods:{
			getList(){
				this.status = "loading";
				this.$http('/api/user/user_collect',{
					page:this.page
				}).then(data=>{
					data.forEach((item)=>{
						this.$set(item,'type',true)
					})
					if (data.length < 10) {
						this.status = "nomore"
					} else {
						this.page = this.page + 1
						this.status = "loadmore"
					}
					this.list = this.list.concat(data)
					uni.stopPullDownRefresh();
				})
			},
			del(id){
				this.$http('/api/common/cancel_collect',{
					shop_id:id
				}).then(data=>{
					uni.showToast({
						title:'取消成功'
					})
					this.list = this.list.filter(item=>item.shop_id!=id)
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
